﻿#include "pch.h"

std::string g_MultipartDir = "./upload";

WEBOAT_MODIFICATION WoServerPtr WEBOAT_API WoCreateServer(WoHttpServerConnectionProviderPtr cpPtr, WoHttpConnectHanderPtr connectPtr) {
	return oatpp::network::Server::createShared(cpPtr, connectPtr);
}

WEBOAT_MODIFICATION void WEBOAT_API WoServerRun(WoServerPtr& serverPtr) {
	g_logger->info("开始监听: {}:{}", g_host,g_port);
	//g_logger->info("监听端口: {}", g_port);
	try {
		serverPtr->run();
	}/*
	catch (const std::exception&err) {
		std::cout<<"404";
	}*/
	catch (...) {
		//std::rethrow_exception(std::current_exception());

	}
};

WEBOAT_MODIFICATION void WEBOAT_API WoServerStop(WoServerPtr& serverPtr) {
	g_logger->info("关闭服务器");
	serverPtr->stop();
};

WEBOAT_MODIFICATION bool WEBOAT_API WoServerIsRuning(WoServerPtr& serverPtr) {
	auto status = serverPtr->getStatus();
	return (status != oatpp::network::Server::STATUS_STOPPING)&&
		(status != oatpp::network::Server::STATUS_DONE);
};

bool WEBOAT_API WoServerSetMultipartDir(const char* path) {
	g_MultipartDir = path;
	auto r = std::filesystem::create_directory(g_MultipartDir);
	if (!r) {
		return false;
	}
	r = std::filesystem::exists(g_MultipartDir);
	if (!r) {
		return false;
	}
	g_MultipartDir = path;
	return true;
}